﻿// ***********************************************************************
// Assembly         : Admin.Framework.Core.Application
// Author           : xwltz
// Created          : 2019-05-25
//
// Last Modified By : xwltz
// Last Modified On : 2019-05-25
// ***********************************************************************
// <summary>
//  应用层基类
// </summary>
// ***********************************************************************

using System.Collections.Generic;
using Admin.Framework.Core.Domain.Core;
using Admin.Framework.Core.Repository.Interface;

namespace Admin.Framework.Core.Application
{
    public class BaseApplication<TEntity> where TEntity : BaseEntity, new()
    {
        /// <summary>
        /// 用于普通的数据库操作
        /// </summary>
        /// <value>The repository.</value>
        protected IRepository<TEntity> Repository;

        public BaseApplication(IRepository<TEntity> repository)
        {
            Repository = repository;
        }

        #region 可以自由扩展方法

        public TEntity Get(int id)
        {
            return Repository.GetSingle(x => x.Id == id);
        }

        /// <summary>
        /// 按实体删除
        /// </summary>
        /// <param name="entity"></param>
        public bool Delete(TEntity entity)
        {
            return Repository.Delete(entity);
        }

        public List<TEntity> GetList()
        {
            return Repository.GetList();
        }

        #endregion
    }
}
